package Hot_100;

import org.junit.Test;

public class T48_rotate {
    @Test
    public void test() {
        int[][] matrix = new int[3][4];
        System.out.println(matrix.length);    // 获取的是行数，
        System.out.println(matrix[0].length); // 要获取列数,可以用matrix[i].length
    }

    public void rotate(int[][] matrix) {
        int n = matrix.length;    //因为是n*n,所以n既是行数也是列数

//        进行转置
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }

//        镜像
        for (int i = 0; i < n; i++) {
            int l = 0, r = n - 1;
            while (l < r) {
                int tmp = matrix[i][l];
                matrix[i][l] = matrix[i][r];
                matrix[i][r] = tmp;
                l++;
                r--;
            }
        }
    }
}
